/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package projetlif13.tools;

import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;

/**
 *
 * @author Yohan B. Sauvegarde et chargement de préférences à partir d'un
 * fichier properties géré par la jvm.
 */
public class PreferencesBundler {

    private static Preferences preferences;

    public static void load() {
        preferences = Preferences.userRoot();
    }

    public static String getValue(String key, String ifnull) {
        return preferences.get(key, ifnull);
    }

    public static void putValue(String key, Object value) {
        if (value instanceof String) {
            preferences.put(key, (String) value);
        } else if (value instanceof Float) {
            preferences.put(key, ((Float) value).intValue() + "");
        } else if (value instanceof Integer) {
            preferences.put(key, ((Integer) value).intValue() + "");
        } else if (value instanceof Double) {
            preferences.put(key, ((Double) value).intValue() + "");
        }

        try {
            preferences.flush();
        } catch (BackingStoreException ex) {
            Logger.getLogger(PreferencesBundler.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
